package client.ui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class AuthentificationDialog extends JDialog {
	
	private JFrame _parent;
	private JPasswordField _PF_password;
	private JTextField _TF_identifiant;
	private JPanel _P_fields;
	
	public AuthentificationDialog(JFrame parent)
	{
		_parent = parent;
		build();
	}
	
	private void build()
	{
		GridBagLayout _formGrid = new GridBagLayout();
		_P_fields = new JPanel();
		_P_fields.setLayout(_formGrid);
	    
		GridBagConstraints constraints;

		// Champs identifiant
		constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.NONE;
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.insets = new Insets(0,5,0,0);
		JLabel L_identifiant = new JLabel("Identifiant : ");
	    _P_fields.add(L_identifiant, constraints);
	    
	    constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.gridx = 1;
		constraints.gridy = 0;
		constraints.weightx = 1.0;
		constraints.insets = new Insets(0,0,0,5);
		_TF_identifiant = new JTextField(30);
	    _P_fields.add(_TF_identifiant, constraints);
	    
	    // Champs mot de passe
	    constraints = new GridBagConstraints();
	    constraints.fill = GridBagConstraints.NONE;
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.insets = new Insets(5,5,0,0);
		JLabel L_password = new JLabel("Mot de passe : ");
	    _P_fields.add(L_password, constraints);
	    
	    constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.gridx = 1;
		constraints.gridy = 1;
		constraints.weightx = 1.0;
		constraints.insets = new Insets(5,0,0,5);
		_PF_password = new JPasswordField(30) ;
	    _P_fields.add(_PF_password, constraints);
	    setMinimumSize(new Dimension(400, 200));
	    
	}
	
	public int ShowDialog()
	{
		return JOptionPane.showConfirmDialog(_parent, _P_fields, "Authentification", JOptionPane.OK_CANCEL_OPTION);
	}

	public JFrame getParent() {
		return _parent;
	}

	public void setParent(JFrame _parent) {
		this._parent = _parent;
	}

	public String getPassword() {
		return String.valueOf(_PF_password.getPassword());
	}

	public String getIdentifiant() {
		return _TF_identifiant.getText();
	}
	
}
